package com.stone.utils;

import java.io.Serializable;
import java.util.List;

public class Page implements Serializable{
	
	public  int pageSize = 10;
	
	private int currentPage ;
	
	private int totalRows ;
	
	private int totalPages ;
	
	private List list ;
	
	private Integer[] pageNumbers = new Integer[10];
	
	public Page(){}
	
	public Page(int totalRows,int pageSize){
		this.pageSize=pageSize;
		if(totalRows >= 0){
			this.totalRows = totalRows;
			pageCounter();
		}		
	}
	
	public void pageCounter(){
		if(totalRows % pageSize == 0){
			this.totalPages = totalRows / pageSize;
		}else{
			this.totalPages = totalRows / pageSize + 1;
		}
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}

	public int getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public Integer[] getPageNumbers() {
		if (totalPages <= 10) {
			for (int i = 0; i < totalPages; i++) {
				pageNumbers[i] = i + 1;
			}
		} else {
			if (currentPage < 5) {
				int length = (10 > totalPages ? totalPages : 10);
				for (int i = 0; i < length; i++) {
					pageNumbers[i] = i + 1;
				}
			} else if (currentPage >= 5 && currentPage <= totalPages - 5) {
				for (int i = 0; i < 10; i++) {
					pageNumbers[i] = currentPage-5 + i;
				}
			}else if(currentPage>totalPages-5){
				for (int i = 0; i < 10; i++) {
					pageNumbers[i] = totalPages-9 + i;
				}
			}
		}
		return pageNumbers;
	}

	public void setPageNumbers(Integer[] pageNumbers) {
		this.pageNumbers = pageNumbers;
	}
	
}
